home *** CD-ROM | disk | FTP | other *** search
- /* Checks if a floppy disk drive is ready. Use before doing a disk I/O */
- /* operation in C to avoid the "Abort, Retry, Ignore" message, if the */
- /* door is open. */
- /* */
- /* Compiled using Micrsoft 4.0, but should be adaptable to any library */
- /* that allows calls to BIOS Int routines. */
- /* */
- /* Tom Crosley, SOFTWEST, Sunnyvale, CA (CIS 70205,533) */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <dos.h>
- #include <malloc.h>
-
- #define SECTOR_SIZE 512 /* default sector size */
- #define RETRY 1 /* # of retries */
-
- /* check if a floppy drive is ready using Int 13H Funtion 04 (Verify Sector) */
- /* returns TRUE if drive ready, FALSE if not (e.g. drive door open) */
-
- int floppy_rdy(drv)
- char drv; /* 'A' or 'B' */
- {
- int cnt;
- union REGS inregs, outregs;
- struct SREGS segregs;
- unsigned char far * buffer;
-
- buffer = malloc(SECTOR_SIZE); /* allocate temp sector buffer */
- cnt = 0;
- while (1) {
- inregs.h.ah = 0x04; /* function # */
- inregs.h.al = 1; /* # of sectors */
- inregs.h.ch = 0; /* 1st cylinder */
- inregs.h.cl = 1; /* 1st sector */
- inregs.h.dh = 0; /* 1st side */
- inregs.h.dl = toupper(drv) - 'A'; /* drive ('A' = 0) */
- segregs.es = FP_SEG(buffer); /* ES:BX pt to buffer (for old BIOS's) */
- inregs.x.bx = FP_OFF(buffer);
- int86x(0x13, &inregs, &outregs, &segregs); /* call Int 13H */
-
- if (!outregs.h.ah) break; /* status ok -- return */
- if (++cnt > RETRY) break; /* already retried */
-
- /* otherwise retry -- first issue reset */
- inregs.h.ah = 0x00; /* function # */
- inregs.h.dl = toupper(drv) - 'A'; /* drive ('A' = 0) */
- int86(0x13, &inregs, &outregs); /* call Int 13H */
- }
-
- free(buffer);
- return(!outregs.h.ah); /* return TRUE if drive ready */
- }
-
- /* Code to test the floppy_rdy function ... */
- /* Execute program drvrdy.exe with a floppy in drive 'A', */
- /* then open the door and try it again. */
- main() {
- printf("Drive 'A' is ");
- if (!floppy_rdy('A')) printf("NOT ");
- printf("ready\n");
- }